package cc.risingsun.wing.core.visitor;

import java.lang.annotation.Annotation;

import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;

import cc.risingsun.wing.annotations.Delete;
import cc.risingsun.wing.annotations.Insert;
import cc.risingsun.wing.annotations.NoSQLAccessInterface;
import cc.risingsun.wing.annotations.SQLAccessInterface;
import cc.risingsun.wing.annotations.Select;
import cc.risingsun.wing.annotations.Update;
import cc.risingsun.wing.core.AnnotatedClassVisitor;
import cc.risingsun.wing.core.AnnotatedFieldVisitor;
import cc.risingsun.wing.core.AnnotatedMethodVisitor;

/**
 * 
 * @author iron.yin@gmail.com
 * @sina 2012-9-5
 */

public class DataAccessInterfaceVisitor extends AnnotatedClassVisitor {

	@SuppressWarnings("unchecked")
	private final static Class<? extends Annotation>[] classes = new Class[]{SQLAccessInterface.class, NoSQLAccessInterface.class};
	
	public DataAccessInterfaceVisitor() {
		super(classes);
	}

	@Override
	protected AnnotatedFieldVisitor getAnnotatedFieldVisitor(
			FieldVisitor superVisitor) {
		return new DataAccessFieldVisitor(superVisitor);
	}

	@Override
	protected AnnotatedMethodVisitor getAnnotatedMethodVisitor(
			MethodVisitor superVisitor) {
		return new DataAccessMethodVisitor(superVisitor);
	}
	

	private static class DataAccessMethodVisitor extends AnnotatedMethodVisitor {
		
		@SuppressWarnings("unchecked")
		public DataAccessMethodVisitor(MethodVisitor mv) {
			super(mv, Select.class, Insert.class, Update.class, Delete.class);
		}
		
	}
	
	private static  class DataAccessFieldVisitor extends AnnotatedFieldVisitor{
		@SuppressWarnings("unchecked")
		public DataAccessFieldVisitor(FieldVisitor fv) {
			super(fv);
		}
	}

}
